package com.sw.bbs.board.controller;

import com.sw.bbs.board.service.MediaService;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Desc: No Desc
 * @Author: wusonghe
 * @Date: 2019/5/27 10:41
 */
@Api(value = "编辑器模块", description = "编辑器", tags = {"Editor Module"})
@RestController("/upload/")
@Slf4j
public class UploadController {

    @Autowired
    private MediaService mediaService;

    @PostMapping("/editor")
    @ResponseBody
    public Object uploadEditor(@RequestParam("file") MultipartFile multipartFile) throws IOException {

        String result = mediaService.upload(multipartFile);
        return new WangEditorResponse("0",result);
    }
    @Data
    private class WangEditorResponse{
        String errno;
        List<String> data;
        public WangEditorResponse(String errno,List<String> data){
            this.errno=errno;
            this.data=data;
        }
        public WangEditorResponse(String errno,String data){
            this.errno=errno;
            this.data=new ArrayList<>();
            this.data.add(data);
        }
    }
}

